
<template>
  <div class="my">
    <div class="top">
      <img
        src="../../assets/images/icon/common resource/hdpi/common_icon_back_white_n.png"
        alt=""
        @click="gotoBack"
      />
      <el-icon class="icon1" style="font-size: 30px" @click="gotoMessage"><Bell /></el-icon>
    </div>
    <div class="user_wrapper">
      <div class="userInfo">
         <Image class="userimg" :dataSrc="userImg"></Image>
        <span class="nickname">{{ userName }}</span>
      </div>
      <div class="userSign" @click="handleSign">签到</div>
    </div>
    <div class="myConsultation">
      <h3 class="title">我的问诊</h3>
      <van-cell is-link @click="gotomywenzhen">
        <template #icon>
          <img src="../../assets/images/image/hdpi/the_current_inquiry.png" alt="" />
        </template>
        <template #title>
          <span>当前问诊</span>
        </template>
      </van-cell>
      <van-cell is-link @click="gotohistorywenzhen">
        <template #icon>
          <img src="../../assets/images/image/hdpi/historical_inquiry.png" alt="" />
        </template>
        <template #title>
          <span>历史问诊</span>
        </template>
      </van-cell>
    </div>
    <div class="menu">
      <van-grid :column-num="3">
        <van-grid-item
          v-for="(value, index) in MenuList"
          :key="index"
          :text="value.text"
          @click="() => gotoGrid(index)"
        >
          <template #icon>
            <van-icon :name="value.icon" size="36" />
          </template>
        </van-grid-item>
      </van-grid>
    </div>
  </div>
</template>
<script setup lang="ts">
import { useRouter } from 'vue-router'
import './my1.scss'
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import { addSign } from '@/api/search'
import Image from '@/components/image/index.vue'
const isFlag = ref(localStorage.getItem('isFlag'))
const userName = JSON.parse(localStorage.getItem('result') as string).nickName
const userImg = JSON.parse(localStorage.getItem('result') as string).headPic
const userId = ref(parseInt(localStorage.getItem('userId') as string))
const sessionId = ref(JSON.parse(localStorage.getItem('sessionId') as string))
const router = useRouter()
const gotomywenzhen = () => {
  router.push('/current')
}
const gotohistorywenzhen = () => {
  router.push('/history')
}
const gotoBack = () => {
  router.push('/home')
}
const gotoMessage = () => {
  router.push('/information')
}
const handleSign = async () => {
  const res = await addSign(userId.value, sessionId.value)
  console.log(res)
  ElMessage.success(res.data.message)
}
const gotoGrid = (index: number) => {
  switch (index) {
    case 0:
      router.push('/files')
      return
    case 1:
      router.push('/mywallet')
      return
    case 2:
      router.push('/collect')
      return
    case 3:
      router.push('/suggestion')
      return
    case 4:
      router.push('/purchase')
      return
    case 5:
      router.push('/mypatient')
      return
    case 6:
      router.push('/interest')
      return
    case 7:
      router.push('/task')
      return
    case 8:
      router.push('/manage')
      return
  }
}
const MenuList = [
  {
    icon: '../../src/assets/images/icon/common resource/hdpi/my_icon_file_n.png',
    text: '我的档案'
  },
  {
    icon: '../../src/assets/images/icon/common resource/hdpi/my_icon_wallet_n.png',
    text: '我的钱包'
  },
  {
    icon: '../../src/assets/images/icon/common resource/hdpi/common_button_collection_small_n.png',
    text: '我的收藏'
  },
  {
    icon: '../../src/assets/images/icon/common resource/hdpi/my_icon_advice_n.png',
    text: '被采纳建议'
  },
  {
    icon: '../../src/assets/images/icon/common resource/hdpi/my_icon_video_n.png',
    text: '我的视频'
  },
  {
    icon: '../../src/assets/images/icon/common resource/hdpi/my_icon_circle_n.png',
    text: '我的病友圈'
  },
  {
    icon: '../../src/assets/images/icon/common resource/hdpi/common_icon_attention_large_n.png',
    text: '我的关注'
  },
  {
    icon: '../../src/assets/images/icon/common resource/hdpi/my_icon_task_n.png',
    text: '我的任务'
  },
  {
    icon: '../../src/assets/images/icon/common resource/hdpi/my_icon_set_n.png',
    text: '设备管理'
  }
]
</script>
